// pages/personal/personal_pelease/personal_pelease.js
var utils = require('../../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
var codeName = getApp().globalData.codeName;
var userId = getApp().globalData.userId;
//ID删除发布信息
function del(that){
  utils.http(httpUrl + "deletePublish", {
    code: codeName,
    userid: userId,
    cateid: that.data.id,
    houseid: that.data.idd
  }, function (res) {
    console.log(res);
    that.getLoad();
  })
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.getLoad();
  },  

  getLoad:function(e){
    var that=this;
    utils.http(httpUrl + "getUserPublish", {
      code: codeName,
      userid: userId,
      cityid: wx.getStorageSync("city").cityid
    }, function (res) {
      console.log(res);
      var cateinfolist = [];
      for (var index in res.cate) {
        if (res.cate[index].content == undefined) {
          res.cate[index].content = "";
        }
        //文字截取
        var sub = res.cate[index].content.substring(0, 40);
        var subContent = sub + "...";
        that.setData({
          advlist: res.cate[index].advlist
        })
        that.data.advlist.length = 3;
        res.cate[index].collect = !res.cate[index].collect;

        var catePost = {
          advlist: that.data.advlist,
          subAdvlist: res.cate[index].advlist, //截取后的图片
          city: res.cate[index].city,
          code: res.cate[index].code,
          collectby: res.cate[index].collectby,
          content: res.cate[index].content,
          subContent: subContent,//截取后的属性
          createTime: res.cate[index].createTime,
          id: res.cate[index].id,
          index: res.cate[index].index,
          collect: res.cate[index].collect,
          ischoiceness: res.cate[index].ischoiceness,
          istop: res.cate[index].istop,
          lookby: res.cate[index].lookby,
          publishby: res.cate[index].publishby,
          title: res.cate[index].title,
          type: res.cate[index].type,
          user: res.cate[index].user,
          isstare: false

        }
        cateinfolist.push(catePost);

      }
      that.setData({
        cate: cateinfolist,
        house: res.house,
        user:res.user
      })

      console.log(that.data.cate);

    })
  },
  //全文和收起
  noStareTap: function (e) {
    var index = e.currentTarget.dataset.index;
    this.data.cate[index].isstare = !this.data.cate[index].isstare;
    this.setData({
      cate: this.data.cate
    })
  },
  //删除美食
  deltypemeishitap:function(e){
    var id = e.currentTarget.dataset.id;
    this.setData({
      id:id
    })
    del(this);
    
  },

   //删除房屋
  deltypejiajutap: function (e) {
    var idd = e.currentTarget.dataset.idd;
    this.setData({
      idd: idd
    })
    del(this);
    
  },


  // //点击头像进入个人主页
  // onPersonalHomeTap: function (e) {
  //   var modelid = e.currentTarget.dataset.modelid;
  //   wx.navigateTo({
  //     url: '../../gourmet/gourmet_details/gourmet_details?modelid=' + modelid,
  //   })
  // },

 
})